<?php

class ProduitReel extends genericClass
{
  function Save()
  {

      if (sizeof($this->Parents)){
	foreach( $this->Parents as $Parent ) {
	  if ( $Parent["Titre"]=="Produit" && $this->Id=="") {
	    $R = $GLOBALS["Systeme"]->Modules[$this->Module]->callData("Boutique/Produit/".$Parent["Id"]);
	  }
	}
      }
      else $R = $GLOBALS["Systeme"]->Modules[$this->Module]->callData("Boutique/Produit/ProduitReel/".$this->Get("Id"));
      $P = $R[0];
    if ($this->Get("Reference")=="") {
      $N = $Tab=$GLOBALS['Systeme']->Modules[$this->Module]->callData("Boutique/Produit/".$P["Id"]."/ProduitReel");
      $N = count($N);
      if ($P["Type"]!="Options")
      {
          if (!$this->Get("DateDispo") || $this->Get("DateDispo")==0)
            {      
		$this->Set("DateDispo",mktime(0,0,0) );                
            }
          if (!$this->Get("DateExpiration") || $this->Get("DateExpiration")==0)
            {
                $DD  = $this->Get("DateDepart");
                if ( strpos($DD,"/") !== false) {
                    $DDT = explode("/",$DD);
                    $DD = mktime(0,0,0,$DDT[1],$DDT[0],$DDT[2] );
                    
                }
		$this->Set("DateExpiration",$DD-86400*2);
                
            }          
      }
      if ($this->Get("Permanent")==1)
	$var = "PER";
      else if ($this->Get("DateDepart"))
	$var = $this->Get("DateDepart");
      else if ($this->Get("DateDispo"))
	{
	  $var = $this->Get("DateDispo");
	}
      $this->Set("Reference",$P["Id"]."-".$N."-".str_replace('/','',$var));
      //DateDispo, Date Expi
    }
    genericClass::Save();
    // On ajoute les options nécessaire
    if ($P["Type"]!="Options"){
        $R = $GLOBALS["Systeme"]->Modules[$this->Module]->callData("Boutique/ProduitReel/VoyageReel=".$this->Id);
        if ( $this->Id!="" ) {
            if (is_array($R)) foreach ($R as $A) { $E = genericClass::createInstance("Boutique",$A);$E->Delete();}   
        }
        if ( is_array($_POST["geth2"]) ) foreach($_POST["geth2"] as $OptCrea){
              $Prix = $_POST["geth2_".$OptCrea];
              if (empty($Prix)) $Prix = 0.0;      
              $Opt = genericClass::createInstance("Boutique","ProduitReel");
              $Opt->Set("Tarif",$Prix);
              $Opt->AddParent("Boutique/Produit/".$OptCrea);
              $Opt->Set("DateDispo",$this->Get("DateDepart"));
              $Opt->Set("DateExpiration",$this->Get("DateRetour"));
              $Opt->Set("VoyageReel",$this->Id);
              $Opt->Save();
          }
    }
  }
}

?>
